package com.kk.goGame.utils;
/*
 *@author KK on 2023.02.17 17:21
 */

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolUtils {
    private static ThreadPoolExecutor threadPoolExecutor;

    static {
        int coreThreadNum = Runtime.getRuntime().availableProcessors() * 3;
        int maxThreadNum = Runtime.getRuntime().availableProcessors() * 4;
        threadPoolExecutor = new ThreadPoolExecutor(
                coreThreadNum,
                maxThreadNum,
                6,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }

    public static void submit(Runnable runnable) {
        threadPoolExecutor.submit(runnable);
    }
}
